<template>
  <div class="user_detail">
    <el-form ref="form" :data="form" :label-width="formLabelWidth">
      <el-form-item label="头像">
        <el-upload
          class="avatar-uploader"
          action="">
          <img v-if="form.image_url" :src="form.image_url" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>

      <el-form-item label="昵称">
        <el-input v-model="form.nickName"/>
      </el-form-item>

      <el-form-item label="性别">
        <el-input v-model="form.gender"/>
      </el-form-item>

      <el-form-item label="注册时间">
        <el-input v-model="form.created_at"/>
      </el-form-item>

      <el-form-item label="留言">
        <el-input v-model="form.message" style="width:300px;" type="textarea" rows="6" placeholder="备注" clearable/>
      </el-form-item>

      <el-form-item>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>

<script>
import userApi from '@/api/user.js'
export default {
  data() {
    return {
      formLabelWidth: 120 + 'px',
      form: {}
    }
  },
  computed: {
    isEdit() {
      return this.$route.meta.isEdit
    },
    id() {
      return this.$route.params.id
    }
  },
  created() {
    this.getUserById()
  },
  methods: {
    // 根据id获取user
    async getUserById() {
      const result = await userApi.getUserById(this.id)
      this.form = result.data[0]
      if(result.data[0].gender == 1) {
        this.form.gender = '男'
      }else {
        this.form.gender = '女'
      }
    },
    // 返回
    goBack() {
      this.$router.go(-1)
    }
  },
  inject: ['reload']
}
</script>
<style lang="less" scoped>
  .user_detail {
    margin-top: 20px;
    .el-input {
      width: 300px;
    }
    .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
